#include "Self_Defined_Functions.h"

Benchmarks* generateFuncObj(int funcID)
{
	Benchmarks *fp;
	// run each of specified function in "configure.ini"
	if (funcID==1){
		fp = new F1();
	}else if (funcID==2){
		fp = new F2();
	}else if (funcID==3){
		fp = new F3();
	}else if (funcID==4){
		fp = new F4();
	}else if (funcID==5){
		fp = new F5();
	}else if (funcID==6){
		fp = new F6();
	}else if (funcID==7){
		fp = new F7();
	}else if (funcID==8){
		fp = new F8();
	}else if (funcID==9){
		fp = new F9();
	}else if (funcID==10){
		fp = new F10();
	}else if (funcID==11){
		fp = new F11();
	}else if (funcID==12){
		fp = new F12();
	}else if (funcID==13){
		fp = new F13();
	}else if (funcID==14){
		fp = new F14();
	}else if (funcID==15){
		fp = new F15();
	}else if (funcID==16){
		fp = new F16();
	}else if (funcID==17){
		fp = new F17();
	}else if (funcID==18){
		fp = new F18();
	}else if (funcID==19){
		fp = new F19();
	}else if (funcID==20){
		fp = new F20();
	}else{
		cerr<<"Fail to locate Specified Function Index"<<endl;
		exit(-1);
	}
	return fp;
}


int initialization(double **p,double **v,Benchmarks *fp)
{
	boost::mt19937 generator(time(0)*rand());
	boost::uniform_real<> uniform_real_generate_x(fp->getMinX(), fp->getMaxX());
	boost::variate_generator< boost::mt19937&, boost::uniform_real<> > random_real_num_x( generator, uniform_real_generate_x );

	int i,j;
	for(i=0;i<populationsize;i++)
	{
		for(j=0;j<dim;j++)
		{
			p[i][j]= random_real_num_x();
			v[i][j]= 0 ;
		}

	}
	return 0;
}

//calculate the fitness of one swarm
void Fitness_Computation( double *results, double **population, int &gbest, int num, int dim, int &FEs, Benchmarks* fp )
{   // num is the population size and dim is the size of dimensions
    int i;
    double best = results[0] = fp->compute( population[0] );
    gbest = 0;
    FEs++;
    for( i = 1; i < num; ++i )
    {
        results[i] = fp->compute( population[i]);

        if( results[i] < best )
        {
            best = results[i];
            gbest = i;

        }
    FEs++;
    }
}

bool Compare_NewType( NewType data1, NewType data2 )
{
    return data1.data < data2.data;
}
